<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <el-card class="box-card box_top">
    <span>设备编号:</span>
    <el-input
      v-model="input"
      placeholder="请输入"
    ></el-input>

    <button
      class="btn"
      @click="chaxun"
    > <i class="el-icon-search"></i> 查询</button>
  </el-card>
</template>

<script>
import { getsearchList } from '@/api/fixing/fixing'
export default {
  props: ['list'],
  data () {
    return {
      input: ''
      // Fmlist:[]
    }
  },
  methods: {
    async chaxun () {
      if (this.input) {
        const fmlist = this.list.find(item => item.number === this.input)

        this.$emit('changeFm', fmlist)
        this.input = ''
      } else {
        const res = await getsearchList({
          pageIndex: 1,
          pageSize: 10
        })
        const Fmdata = res.data.currentPageRecords.map((item, index) => {
          return {
            num: index + 1,
            number: item.innerCode,
            model: item.type?.name ? item.type.name : '',
            address: item.node?.name ? item.node.name : '',
            partners: item.ownerName ? item.ownerName : '',
            state: item.vmStatus === 1 ? '运营' : '' || item.vmStatus === 0 ? '未投放' : '' || item.vmStatus === 3 ? '撤机' : ''
          }
        })
        this.$emit('changeFm', Fmdata)
      }
    }
  }
}
</script>

<style lang="less" scoped>
::v-deep .el-select{
  width: 380px;
}
  .box_top {
    ::v-deep .el-card__body {
      height: 40px;
      line-height: 60px;
      padding: 0 10px 25px 10px;
      span {
        text-align: right;
        vertical-align: middle;
        font-size: 14px;
        color: #606266;
        line-height: 40px;
        padding: 0 12px 0 0;
      }
      .el-input {
        width: 200px;
        margin-left: 10px;
      }
      .btn {
        height: 38px;
        width: 80px;
        margin-left: 20px;
        border: none;
        color: #fff;
        background-color: #6c8bf6;
        border-radius: 4px;
        font-weight: 400px;
        font-size: 13px;
        cursor: pointer;
        text-align: center;
        line-height: 38px;
      }
    }
  }
</style>
